package com.xpqh.ksg.common.persistence.dao;

import com.xpqh.ksg.common.persistence.model.KsgUserNotice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xpqh.ksg.modular.users.dto.KsgUserNoticeRespDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户通知记录 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2025-04-16
 */
public interface KsgUserNoticeMapper extends BaseMapper<KsgUserNotice> {

    @Select("select a.id, b.title, b.content, b.target_url targetUrl, b.create_date createDateStr from ksg_user_notice a left join ksg_user_notice_entity b on a.notice_id = b.notice_id where a.user_id = #{userId} and a.is_read = 0 order by a.id desc")
    List<KsgUserNoticeRespDTO> getNoticeList(@Param("userId")Integer userId);

    @Update("update ksg_user_notice set is_read = 1 where user_id = #{userId} and is_read = 0")
    void updateNoticeReadStatusByUserId(@Param("userId") Integer userId);

    @Select("select count(1) from ksg_user_notice where user_id = #{userId} and is_read = 0")
    Integer getUserUnReadCount(Integer userId);
}

